package com.yileiqian.alg;

public class OneInInteger {

	public static int getOneInInteger(int value) {
		int num = 0;
		for (int i = 3; i >= 0; --i) {
			num += getOneInByte((byte) (value & 0xff));
			value >>= 8;
		}
		return num;
	}

	private static int getOneInByte(byte b) {
		int num = 0;
		while (b != 0) {
			b &= b - 1;
			num++;
		}
		return num;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(getOneInInteger(7));
	}

}
